import style from '@/assets/components.module.scss';

import {} from '@/components';

export interface ProjectProps {
    children?: string | React.ReactElement | React.ReactElement[];
}

function Project({ children }: ProjectProps) {
    console.log(time().format('{YYYY} HH:mm:ss'), `login render`);

    // localStorage.setItem('id', '1');
    const history = withRouter();

    const [name, set_name] = useState('');
    const [word, set_word] = useState('');

    return (
        <>
            <div className={style['login']}>
                <input
                    type='text'
                    placeholder='账号'
                    onChange={(e) => {
                        set_name(e.target.value);
                    }}
                />
                <input
                    type='text'
                    placeholder='密码'
                    onChange={(e) => {
                        set_word(e.target.value);
                    }}
                />
                <div>
                    <button
                        onClick={() => {
                            axios
                                .post(`user?username=${name}&password=${word}`)
                                .then((res) => {
                                    if (res.data === '用户名或密码错误') {
                                        alert('账号或密码错误');

                                        return;
                                    }

                                    localStorage.setItem('id', res.data);
                                    history.push('/home');
                                });
                        }}>
                        login
                    </button>
                </div>
            </div>
        </>
    );
}

export default Project;
